var LOAN_CIG = {pageIndex:0, amountId:0, periodId:0, lendType:0, keyWord:'', orderBy:0};

//打开
function openArea(){
    $("#areaMask").fadeIn();
    $("#areaLayer").animate({"bottom": 0});
}
//关闭
function closeArea(){
    $("#areaMask").fadeOut();
    $("#areaLayer").animate({"bottom": "-100%"});
    $("#areaBox").scrollTop(0);
    $("#backUp").removeAttr("onClick").hide();
}
var areaList = $("#areaList"),closeAreaBtn= $("#closeArea");
// 初始化数据
function initArea(arr,target_obj){
    var _input_box = target_obj;
    var areaData = "";
    for (var i=0; i<arr.length; i++) {
        // console.log(arr[i]);
        areaData += '<li><a>' + arr[i] + '</a></li>';
    }
    areaList.html("").html(areaData);
    $("#areaBox").scrollTop(0);
    areaList.find("li").on('click',function(){
        var _input_value = $(this).find('a').text();
        // console.log(_input_value);
        _input_box.val(_input_value);
        closeArea();
    });
    closeAreaBtn.unbind("click").on("click",function(){
        closeArea();
    });
}

$(function(){
    $(".main_image")[0] != undefined ? $(".main_image").banner_round() : '';
    $("#marquee_box")[0] != undefined ? $("#marquee_box").font_scroll({time: 2000,num: 1}) : '';
    // 找贷款
    $.fn.loan_nav = function(){
        var _self = $(this),
            _select_textdiv_list = $(".select_textdiv"),
            _list = $("#content-list"),
            _select_first_li = _self.children().children().find(".select_first_ul li");
        //  四个条件搜索页
        _select_textdiv_list.on('click',function () {
            var _select_textdiv = $(this);
            _select_textdiv.removeClass("divfocus");
            _select_textdiv.addClass("divfocus");
            _select_textdiv.parent().parent().siblings().find(".select_textul").hide();
            _select_textdiv.siblings(".select_textul").fadeToggle(500);

            var _select_textdiv_list_li = _select_textdiv.parent().find("li");
            _select_textdiv_list_li.unbind("click").on("click",function(){
                var _li = $(this);
                var choosed_txt = _li.find("p").text();
                var choosed_id = _li.find("p").attr("itemid");
                //console.log(choosed_id);
                _li.removeClass("focus");
                _li.addClass("focus").siblings("li").removeClass("focus");
                _li.parents(".select_textul").siblings(".select_textdiv").find(".s_text").text(choosed_txt).addClass("colf0706f");
                _li.parents(".select_textul").siblings(".select_textdiv").find(".iconfont").html('&#xe657;').addClass('colf0706f');
                _select_textdiv.find("input").val(choosed_id);
                //console.log(_select_textdiv.find("input").val(choosed_id));
                _li.parents(".select_textul").fadeOut(300,function(){
                    // 条件选择好发送请求
                    return get_loan_list();
                });
            });
        });
        var get_loan_list = function(){
            LOAN_CIG.pageIndex = 0;
            LOAN_CIG.amountId = parseInt(0 + $("#amount_id").val());
            LOAN_CIG.periodId = parseInt(0 + $("#period_id").val());
            LOAN_CIG.lendType = parseInt(0 + $("#lend_id").val());
            LOAN_CIG.orderBy = parseInt(0 + $("#orderby").val());
            LOAN_CIG.keyWord = ($("#keyWord").val());
            scrollPagination_obj.contentData.amount_id = LOAN_CIG.amountId;
            scrollPagination_obj.contentData.period_id = LOAN_CIG.periodId;
            scrollPagination_obj.contentData.lend_id = LOAN_CIG.lendType;
            scrollPagination_obj.contentData.keyWord = LOAN_CIG.keyWord;
            scrollPagination_obj.contentData.orderby = LOAN_CIG.orderBy;

            //console.log(LOAN_CIG);
            layer.open({type:2});
            $.ajax({
                url: "/ajax/ajax_search_more_loan_json_new",
                async: true,
                type: "post",
                dataType: "html",
                data: {pageIndex:LOAN_CIG.pageIndex,amount_id:LOAN_CIG.amountId,period_id:LOAN_CIG.periodId,lend_id:LOAN_CIG.lendType,keyWord:LOAN_CIG.keyWord,orderby:LOAN_CIG.orderBy},
                timeout: 10000,
                success: function(data) {
                    layer.closeAll();
                    LOAN_CIG.pageIndex++;
                    scrollPagination_obj.contentData.pageIndex = LOAN_CIG.pageIndex;
                    return _list.html(data).attr("scrollpagination","enabled");
                },
                error: function() {}
            });

        }
    };
    $("#top-menu").loan_nav();

    $.fn.loan_change = function(){
        var currentPage = 0;
        var _btnChange = $('#for-change');
        var _hotLoanList = $('#hot-loan');
        _btnChange.on('click',function () {
            _hotLoanList.empty();
            currentPage = currentPage + 1;
            _hotLoanList.fadeIn(1000,function () {
                return get_hot_list(currentPage);
            })
        });
        var get_hot_list = function(pageIndex) {
            $.ajax({
                url: "/ajax/ajax_index_more_loan_json",
                async: true,
                type: "post",
                dataType: "html",
                data: {pageIndex:pageIndex},
                timeout: 10000,
                success: function(data) {
                    return _hotLoanList.html(data);
                },
                error: function() {}
            });
        }
    };
    $("#for-change").loan_change();
});

